package com.wandian.texas.dao.Impl;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.wandian.texas.db.DBMgr;
import com.wandian.texas.db.WandianBaseDao;
import com.wandian.texas.entity.AnnounceEntity;
import com.wandian.util.Log;

/**
 * @author long
 * @Create 2012-10-27 上午10:59:09
 * @QQ 108232706
 * @version 1.0
 * @description LobbyDaoImpl
 */
public class LobbyDaoImpl extends WandianBaseDao {

	public LobbyDaoImpl(DBMgr _dbMgr) {
		super(_dbMgr);
	}

//	@Override
//	protected Connection openConn() {
//		return this.dbMgr.getDbWandian();
//	}

	public List<AnnounceEntity> getAnnouce() {
		List<AnnounceEntity> announces = new ArrayList<AnnounceEntity>();
		String sqlText = "select * from [Mutil_TexasPoker].[dbo].t_PublicMsg WHERE  isShow=1 and isValid=1;";
		Statement stmt = this.getStatement();
		ResultSet rs = null;
		AnnounceEntity info = null;
		this.dbMgr.lock.lock();
		try {
			this.dbMgr.setCurrentDb(DBMgr.TexasPokerDB);
			if (stmt != null) {
				rs = stmt.executeQuery(sqlText);
				if (rs != null) {
					while (rs.next()) {
						info = new AnnounceEntity();
						info.id = rs.getInt("Id");
						info.title = rs.getString("Title");
						info.announcement = rs.getString("Announcement");
						info.startTime = rs.getTimestamp("StartTime");
						info.endTime = rs.getTimestamp("EndTime");
						info.orderNum = rs.getInt("OrderNum");
						announces.add(info);
					}
				}
			}
		} catch (Exception e) {
			info = null;
			Log.error("执行出错" + sqlText, e);
		} finally {
			closeConn(stmt, rs);
			this.dbMgr.lock.unlock();
		}
		return announces;
	}
}
